package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.SetMealMapper;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("C端userSetmeal")
@RequestMapping("/user/setmeal")
@Api(tags = "设置套餐接口")
@Slf4j
public class SetMealController {
    @Autowired
    private SetMealService setMealService;
    @Autowired
    private SetMealMapper setMealMapper;
    /**
     * 套餐按分类查询
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/{categoryId}")
    @ApiOperation("套餐按分类查询")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result<List<Setmeal>> list(long categoryId){
        List<Setmeal> list = setMealMapper.list(categoryId);
        return Result.success(list);
    }
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询菜品")
    public Result<List<SetmealDish>> getByID(@PathVariable long id){
        List<SetmealDish> list = setMealService.getSetmealDish(id);
        return Result.success(list);
    }


}
